package chabernac.android.wordbattle;

import chabernac.android.wordbattle.model.WordRaster;
import chabernac.android.wordbattle.paint.iDrawableFactory;
import chabernac.android.wordbattle.paint.boggle.BoggleStyleDrawableFactory;
import chabernac.android.wordbattle.paint.bogglemerge.BoggleMergeDrawableFactory;
import chabernac.android.wordbattle.paint.bogglesimple.SimpleBoggleDrawableFactory;
import chabernac.android.wordbattle.paint.classic.HighlightDrawableFactory;
import chabernac.android.wordbattle.paint.crosstile.CrossTitleWordRasterFactory;

public class WordRasterGameMediatorFactory {
  public enum GameType{
    BOGGLE_STYLE,
    SIMPLE_BOGGLE_STYLE,
    SNAKE_SIMPLE_BOGGLE_STYLE,
    BOGGLE_MERGE,
    CLASSIC_STYLE,
    BOGGLE_CROSSTILE,
  }
  
  public static WordRasterGameMediator createGame(GameType aGameType, String aLanguage, int aRows, int aColumns){
	  switch(aGameType)
	  {
	  case BOGGLE_STYLE:
		  return createBoggleStyleMediator( aLanguage, aRows, aColumns );
	  case SIMPLE_BOGGLE_STYLE:
		  return createSimpleBoggleStyleMediator( aLanguage, aRows, aColumns );
	  case SNAKE_SIMPLE_BOGGLE_STYLE:
		  return createSnakeSimpleBoggleStyleMediator( aLanguage, aRows, aColumns );
	  case BOGGLE_MERGE:
		  return createSnakeBoggleMergeStyleMediator( aLanguage, aRows, aColumns );
	  case CLASSIC_STYLE:
		  return createClassicStyleMediator( aLanguage, aRows, aColumns );
	  case BOGGLE_CROSSTILE:
	      return createBoggleCrossTileMediator( aLanguage, aRows, aColumns );
	  default:
		  return createClassicStyleMediator( aLanguage, aRows, aColumns );
	  }   
  }
  
  public static WordRasterGameMediator createBoggleStyleMediator(String aLanguage, int aRows, int aColumns){
    WordRaster theWordRaster = WordRasterContext.getInstance().getWordRasterFactory().createBoggleRaster(aLanguage, aRows, aColumns, WordRasterContext.getInstance().getStringDatabase());
    theWordRaster.addListener(new VibrateOnWordFoundListener());
    iDrawableFactory theDrawableFactory = new BoggleStyleDrawableFactory();
    WordRasterGameMediator theMediator = new WordRasterGameMediator(theDrawableFactory, theWordRaster, new RenderingHints().setHeightEqualsWidth( false ));
    return theMediator;
  }
  
  public static WordRasterGameMediator createSimpleBoggleStyleMediator(String aLanguage, int aRows, int aColumns){
    WordRaster theWordRaster = WordRasterContext.getInstance().getWordRasterFactory().createBoggleRaster(aLanguage, aRows, aColumns, WordRasterContext.getInstance().getStringDatabase());
    theWordRaster.addListener(new VibrateOnWordFoundListener());
    iDrawableFactory theDrawableFactory = new SimpleBoggleDrawableFactory();
    WordRasterGameMediator theMediator = new WordRasterGameMediator(theDrawableFactory, theWordRaster, new RenderingHints().setHeightEqualsWidth( true ));
    return theMediator;
  }
  
  public static WordRasterGameMediator createSnakeSimpleBoggleStyleMediator(String aLanguage, int aRows, int aColumns){
    WordRaster theWordRaster = WordRasterContext.getInstance().getWordRasterFactory().createSnakeRaster( aLanguage, aRows, aColumns, WordRasterContext.getInstance().getStringDatabase());
    theWordRaster.addListener(new VibrateOnWordFoundListener());
    iDrawableFactory theDrawableFactory = new SimpleBoggleDrawableFactory();
    WordRasterGameMediator theMediator = new WordRasterGameMediator(theDrawableFactory, theWordRaster, new RenderingHints().setHeightEqualsWidth( true ).setShowLastSelectedLetter( true ));
    return theMediator;
  }
  
  public static WordRasterGameMediator createSnakeBoggleMergeStyleMediator(String aLanguage, int aRows, int aColumns){
    WordRaster theWordRaster = WordRasterContext.getInstance().getWordRasterFactory().createSnakeRaster( aLanguage, aRows, aColumns, WordRasterContext.getInstance().getStringDatabase());
    theWordRaster.addListener(new VibrateOnWordFoundListener());
    iDrawableFactory theDrawableFactory = new BoggleMergeDrawableFactory();
    WordRasterGameMediator theMediator = new WordRasterGameMediator(theDrawableFactory, theWordRaster, new RenderingHints().setHeightEqualsWidth( true ).setShowLastSelectedLetter( true ));
    return theMediator;
  }
  
  public static WordRasterGameMediator createClassicStyleMediator(String aLanguage, int aRows, int aColumns){
    WordRaster theWordRaster = WordRasterContext.getInstance().getWordRasterFactory().createBoggleRaster( aLanguage, aRows, aColumns, WordRasterContext.getInstance().getStringDatabase());
//    theWordRaster.addListener(new VibrateOnWordFoundListener());
    iDrawableFactory theDrawableFactory = new HighlightDrawableFactory();
    WordRasterGameMediator theMediator = new WordRasterGameMediator(theDrawableFactory, theWordRaster, new RenderingHints().setHeightEqualsWidth( false ));
    return theMediator;
  }
  
  public static WordRasterGameMediator createBoggleCrossTileMediator(String aLanguage, int aRows, int aColumns){
    WordRaster theWordRaster = WordRasterContext.getInstance().getWordRasterFactory().createBoggleRaster(aLanguage, aRows, aColumns, WordRasterContext.getInstance().getStringDatabase());
    theWordRaster.addListener(new VibrateOnWordFoundListener());
    iDrawableFactory theDrawableFactory = new CrossTitleWordRasterFactory();
    WordRasterGameMediator theMediator = new WordRasterGameMediator(theDrawableFactory, theWordRaster, new RenderingHints().setHeightEqualsWidth( true ));
    return theMediator;
  }
}
